package com.dongdongshop.mongo;

import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.mongodb.core.MongoTemplate;
@SpringBootTest
public class Test1 {

    @Autowired
    private MongoTemplate mongoTemplate;



    @Test
    public void createCollection(){
//       判断要创建的集合是否存在
        if(mongoTemplate.collectionExists("dongdong")){
//            如果存在,先删除,再创建
            mongoTemplate.dropCollection("dongdong");
        }
        mongoTemplate.createCollection("dongdong");
        System.out.println("ok:创建成功");
    }


}
